/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.giohang;

import controller.login.CheckTaiKhoan;
import dao.util.HibernateUtil;
import java.util.ArrayList;
import java.util.Iterator;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Chitietdondathang;
import pojo.Dondathang;
import template.choosePage;

/**
 *
 * @author vinh
 */
@ManagedBean(name = "LichSuMuaHang")
@SessionScoped
public class LichSuMuaHang {

    /**
     * Creates a new instance of LichSuMuaHang
     */
    private ArrayList<Chitietdondathang> chitietddh = new ArrayList();

    public LichSuMuaHang() {
    }

    public void LayLSMH() {
        setChitietddh((ArrayList<Chitietdondathang>) new ArrayList());
        if (CheckTaiKhoan.taikhoan != null) {
            Session session = HibernateUtil.getSessionFactory().openSession();
            String hql = String.format("select obj from %s obj where obj.taikhoan.mataikhoan like '%s'", Dondathang.class.getName(), CheckTaiKhoan.taikhoan.getMataikhoan());
            Query query = session.createQuery(hql);
            //query.setParameter(0,nsx)
            ArrayList<Dondathang> ds = (ArrayList<Dondathang>) query.list();
            session.close();
            //  sess.setAttribute("dsddh", ds);
            for (int i = 0; i < ds.size(); i++) {
                Iterator<Chitietdondathang> chitiet = ds.get(i).getChitietdondathangs().iterator();
                while (chitiet.hasNext()) {
                    Chitietdondathang ct = chitiet.next();
                    getChitietddh().add(ct);
                }

            }
                    choosePage.page="LichSuMuaHang";
                     chitietddh= getChitietddh();
        }
    
        else
        {
            choosePage.page="TrangChu";
        }

    }

    /**
     * @return the chitietddh
     */
    public ArrayList<Chitietdondathang> getChitietddh() {
        return chitietddh;
    }

    /**
     * @param chitietddh the chitietddh to set
     */
    public void setChitietddh(ArrayList<Chitietdondathang> chitietddh) {
        this.chitietddh = chitietddh;
    }
}
